﻿ using System;
using System.Collections.Generic;
using System.Text;
using CMN.DAL;
using CMN.Entity;
using System.Data;
using System.Data.Common;
namespace CMN.BLL
{
     /// <summary>
    ///  (域名记录)
    /// </summary>
    public class Domains
    {
        #region "Domains (域名记录 ) - Method"
        /// <summary>
        /// 新增/删除/修改 DomainsEntity (域名记录)
        /// </summary>
        /// <param name="fam">DomainsEntity实体类</param>
        /// <returns>-1:存储过程执行失败,-2:存在相同的主键,Insert:返回插入自动ID,Update:返回更新记录数,Delete:返回删除记录数</returns>
        public  Int32 InsertUpdateDelete(DomainsEntity fam)
        {
            return DALHelper.CMNHelper.DomainsInsertUpdateDelete(fam);
        }
        /// <summary>
        /// 根据ID返回 DomainsEntity实体类 单笔资料 (域名记录)
        /// </summary>
        /// <param name="ID">ID 主键</param>
        /// <returns>返回 DomainsEntity实体类 ID为0则无记录</returns>
        public  DomainsEntity  Disp(Int32 ID)
        {
            DomainsEntity fam = null;
            QueryParam qp = new QueryParam();
            qp.PageIndex = 1;
            qp.PageSize = 1;
            qp.Where = string.Format("{0}.{1} = {2}", "Domains", "ID", ID);
            int RecordCount = 0;
            List<DomainsEntity> lst = List(qp, out RecordCount);
            if (RecordCount > 0)
            {
                fam = lst[0];
            }
            return fam;
        }

        /// <summary>
        /// 返回DomainsEntity实体类的List对象 (域名记录)
        /// </summary>
        /// <param name="qp">查询类(非安全函数,传入参数请进行Sql字符串过滤)</param>
        /// <param name="RecordCount">返回记录总数</param>
        /// <returns>DomainsEntity实体类的List对象(域名记录)</returns>
        public  List<DomainsEntity> List(QueryParam qp, out int RecordCount)
        {
            qp.TableName = "Domains";
            if (string.IsNullOrEmpty(qp.Orderfld))
            {
                qp.Orderfld = "ID desc";
            }
            if (string.IsNullOrEmpty(qp.ReturnFields))
            {
                qp.ReturnFields = "*";
            }
            if (string.IsNullOrEmpty(qp.NotInRowName))
            {
                qp.NotInRowName = "ID";
            }
            return DALHelper.CMNHelper.DomainsList(qp,true, out RecordCount);
        }
        
        /// <summary>
        /// 批量删除((域名记录))
        /// </summary>
        /// <param name="idList">删除数组</param>
        /// <returns>删除的总个数</returns>
        public  int DelList(string idList)
        {
            string strDel = string.Concat("delete from  Domains where ID in(", idList, ")");
            return DALHelper.CMNHelper.ExecuteNonQuery(CommandType.Text, strDel, null);
        }
        #endregion
   }
 }
 